package com.tledu.zyf.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tledu.zyf.model.Group;

@WebServlet("/servlet/JstlCoreServlet")
public class JstlCoreServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 普通字符串
		request.setAttribute("hello", "helloWord");

		// html 字符串
		request.setAttribute("welcome", "<font color='red'>欢迎 ! </font>");

		// 条件判断
		request.setAttribute("v1", 10);
		request.setAttribute("v2", 20);

		// 集合
		List<Group> groups = new ArrayList<Group>();

		for (int i = 0; i < 5; i++) {
			Group group = new Group("张三_" + i, i, 18);
			groups.add(group);
		}

		request.setAttribute("groups", groups);

		// map
		Map map = new HashMap();

		map.put("k1", "v1");
		map.put("k2", "v2");
		map.put("k3", "v3");

		request.setAttribute("map", map);

		request.setAttribute("str", "1#2#3#4#5#");

		request.getRequestDispatcher("/jstl_core.jsp").forward(request, response);

	}

}
